@extends('admin.layouts.master')
@section('css')
    <link rel="stylesheet" href="{{asset('/css/admin/admin_vip.css')}}">
@endsection
@section('content')
    {{--@include('admin.layouts.message')--}}
    <div class="main_header clearfix">
        <div class="main_header_show clearfix">
            <span><a style="color:white;font-size: 18px" href="{{url('/admin/vip')}}">会员管理</a><span style="color:white;font-size: 18px">&nbsp;&nbsp;>&nbsp;&nbsp;会员详情</span></span>
        </div>

        <div class="main_header_edit clearfix">
            @if(Auth::guard('admin')->user()->checkPermission('vip.edit'))
             <div class="add_box" data-toggle="modal" data-target="#myModal">
                <img src="{{asset('images/update_icon.png')}}" alt="">
                <span>编辑</span>
            </div>
            @endif

                @if(Auth::guard('admin')->user()->checkPermission('vip.status'))
                 <div class="add_box">

                <span style="color: orange;padding-left: 3px;" is_show="{{$masters->status}}" class="change">
                    {{$masters->status==1?'停用用户':'激活用户'}}</span>
            </div>
              @endif
        </div>
    </div>
    <!-- 会员详情 -->
      <div class="main_form clearfix">
        <!-- 会员编辑区 -->
        <div class="main_infolist">
         <div class="main_editarea clearfix">
            <img src="{{asset($masters->img)}}" alt="">
            <div class="peson_infolist clearfix">
                <div class="peson_left clearfix">

                        <li>
                            <span>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名&nbsp;:</span>
                            <span>{{$masters->name}}</span>
                        </li>
                        <li>
                            <span>性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别&nbsp;:</span>
                             <span>{{$masters->sex==1?'男':'女'}}</span>
                        </li>
                        <li>
                            <span>年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龄&nbsp;:</span>
                            <span>{{$masters->age}}</span>
                        </li>

                </div>
                <div class="peson_right">
                     <li>
                            <span>身份证号码&nbsp;:</span>
                            <span>{{$masters->id_card}}</span>
                        </li>
                        <li>
                            <span>&nbsp;&nbsp;&nbsp;联系方式&nbsp;:</span>
                             <span>&nbsp;{{$masters->telphone}}</span>
                        </li>
                        <li>
                            <span>&nbsp;&nbsp;&nbsp;注册日期&nbsp;:</span>
                            <span>&nbsp;{{$masters->created_at}}</span>
                        </li>
                </div>
            </div>
        </div>
        <!-- 用户历史订单 -->
        <div class="history_order">
            <div class="history_order_box">
            <span>用户历史订单</span>
            </div>
        </div>
        <!-- 订单详情表格 -->
        <div class="main_formlist clearfix">
             <table class="table table-bordered main_table">
                <tbody>
                <tr>
                    <th>订单号</th>
                    <th>下单店铺名称</th>
                    <th>总价</th>
                    <th>订单状态</th>
                    <th>购买时间</th>

                </tr>
              @foreach($orders as $order)
                    <tr>
                        <td>{{$order->order_num}}</td>
                        <td>{{$order->shop_name}}</td>
                        <td>{{$order->total}}</td>
                        <td>
                            @if($order->state==0)
                                <span style="color: red;">未付款</span>
                            @else
                                <span>已付款</span>
                           @endif
                        </td>
                        <td>{{$order->created_at}}</td>
                    </tr>
                @endforeach
                </tbody>

            </table>
        </div>
        <div class="boot_fenye">
            <div class="boot_page">
                <div class="boot_page_di">第<span class="">{{ $page = isset($_GET['page'])?$_GET['page']:1}}</span>页
                </div>
                <div  class="boot_page_total">共<span>{{$total_page}}</span>页
                </div>
            <div class="boot_choose">
                {{$orders->render()}}
            </div>
        </div>
        </div>
     </div>
      </div>
@endsection

<!-- Modal -->
<div style="display: none;margin-top: 100px;" class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header" style="background: #3D446B;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="color: white;"><span aria-hidden="true"><img
                                src="{{asset('/images/cancel_icon.png')}}" alt=""></span></button>
                <h4 class="modal-title" id="myModalLabel" style="color: white;text-align: center; font-size: 24px;">编辑</h4>
            </div>
            <form action="" id="addForm" enctype='multipart/form-data' method="post">
                {{csrf_field()}}
                <div class="modal-body">
                    <div class="modal_info clearfix">
                        <p class="blinfo"><span>姓名</span><br>
                            <input type="text" name="name" value="{{$masters->name}}"></p>
                        {{--@if(count($errors) > 0)--}}
                            {{--<div class="" style="color: red;width: 400px;">{{$errors->first('name')}}</div>--}}
                        {{--@endif--}}
                        <p class="blinfo"><span>年龄</span><br>
                            <input type="text" name="age" value="{{$masters->age}}"></p>
                        {{--@if(count($errors) > 0)--}}
                            {{--<div class="" style="color: red;width: 400px;">{{$errors->first('age')}}</div>--}}
                        {{--@endif--}}
                        <p class="blinfo"><span>性别</span><br>
                            <select name="sex" id="" class="blinfo_sex">
                                @if($masters->sex==1)
                                <option value="1" selected>男</option>
                                <option value="0" >女</option>
                                    @else
                                    <option value="1">男</option>
                                    <option value="0"  selected>女</option>
                                @endif
                            </select></p>
                        <p class="blinfo"><span>联系方式</span><br>
                            <input type="text" name="telphone" value="{{$masters->telphone}}"></p>

                        <p class="blinfo"><span>身份证号码</span><br>
                            <input type="text" name="id_card" value="{{$masters->id_card}}"></p>

                    </div>
                </div>
                <div class="modal-footer" style="text-align: center;">
                    <button id="save" type="button" class="btn btn-primary" style="height:40px;border: 0px solid;width: 300px;background: #2BAAF7" >修改</button>
                </div>
            </form>
        </div>
    </div>
</div>
@section('js')
    <script type="text/javascript">
        $(".change").click(function () {
            var is_show = $(this).attr('is_show');
            var mythis = $(this);
            $.ajax({
                url: '/admin/vip/status' ,
                type:'post',
                data: {'is_show': is_show,'id':"{{$masters->id}}"},
                success: function (data) {
                    if (data == 1) {
                        mythis.attr('is_show', '1');
                        mythis.html("停用用户");
                        layer.msg("激活用户");
                    } else {
                        mythis.attr('is_show', '0');
                        mythis.html("激活用户");
                        layer.msg("停用用户");
                    }
                }
            });
        });

    </script>
    {{--编辑弹窗的相关要求,ajax提交,有返回值--}}
    <script>
        $("#save").on("click",function () {
            $.ajax({
                url:"{{url('/admin/vip/update/'.$masters->id)}}" ,
                dataType: 'json',
                data: $('#addForm').serialize(),
                type: 'post',
                success: function (res) {
                    if (res.state == 0) {
                        layer.msg(res.msg);
                    } else {
                        layer.msg(res.msg, {icon: 1}, function () {
                            location.href = "{{url('/admin/vip/show/'.$masters->id)}}";
                        });
                    }
                }
            })
        })
    </script>
@endsection
